define(['app'], function (app) {
    app.register.controller("AppCtrl", ["$scope", "$rootScope", "$http", "$modal", function ($scope, $rootScope, $http, $modal) {
        $rootScope.baseinfo.defaultMenuName = '系统管理';
        $rootScope.baseinfo.defaultSubMenuName = '应用管理';
        $scope.refAppList=function(){
            $http.post('app/list.do', {})
                .success(function (data) {
                    $scope.applist = data.data;
                });
        }
        $scope.addAppUI = function () {
            var scope = $rootScope.$new();
            scope.modal = {
                header: "增加应用",
                btnName: "保存"
            }
            $scope.$modalInstance = $modal.open({
                templateUrl: 'views/application/edit.html',
                controller: "EditAppCtrl",
                scope: scope
            }).result.then(function () {
                    $scope.refAppList();
            }, function () {
                // dismissed here.
                // e.g. backdrop click, escape key press
            });
        }
        $scope.refAppList();

    }]).controller("EditAppCtrl", function ($scope, $modalInstance, $http) {

        $scope.ok = function () {
            var application =$scope.modal;
            $http({
                method: 'POST',
                url: 'app/add.do',
                data: application
            }).success(function (data) {
                $modalInstance.close();
            });

        };

        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };
    });
});